<?php

namespace app\admin\controller\qingdongwms\finance;

use addons\qingdongwms\model\Consume as ConsumeModel;
use app\admin\controller\qingdongwms\Base;
use addons\qingdongwms\model\ConsumeDetail;
use addons\qingdongwms\model\Customer;
use addons\qingdongwms\model\ExamineRecord;
use addons\qingdongwms\model\Staff;

/**
 * 报销管理
 * @icon fa fa-user
 */
class Consume extends Base {
	protected $relationSearch = true;
	protected $searchFields   = 'id,username,nickname';
	/**
	 * @var \addons\qingdongwms\model\Consume
	 */
	protected $model = null;


	public function _initialize() {
		parent::_initialize();
		$this->model = new ConsumeModel();
	}


	/**
	 * 查看
	 */
	public function index() {
		//设置过滤方法
		$this->request->filter(['strip_tags', 'trim']);
		if ($this->request->isAjax()) {
			//如果发送的来源是Selectpage，则转发到Selectpage
			if ($this->request->request('keyField')) {
				return $this->selectpage();
			}
			$condition['consume.check_status'] = ['in',[0,1,2,3]];
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $list = $this->model->where($where)->with(['customer','staff'])
                ->where($condition)->order('id desc')->paginate($limit);

            $result = array("total" => $list->total(), "rows" => $list->items());
            return json($result);
		}

		return $this->view->fetch();
	}

}
